#include<iostream>
#include<vector>
using namespace std;
vector<int> vi, wi;
int n{0}, v{0}, tmp1{0}, tmp2{0};
int dp(int v, int i);


int main()
{ 
    cin >> n >> v;
    for(int i = 0; i < n; i++)
    {
        cin >> tmp1 >> tmp2;
        vi.push_back(tmp1);
        wi.push_back(tmp2);
    }
    cout << dp(v, 0) << endl;
    return 0;
}

int dp(int v, int i)  // 假设一开始不需要那么多的参数，后面再慢慢需要再加上去
{
    if(i >= n) return 0;
    int value1{0}, value2{0};
    if(vi[i] <= v)
    {
        value1 = wi[i] +dp(v-vi[i], i+1); 
        value2 = dp(v, i+1);
    }
    if(value1 > value2) return value1;
    else return value2;
}